#include "LUA_Mouse.h"

int getPositionMouse(lua_State* L){
	int mousePosX;
	int mousePosY;
	SDL_GetMouseState(&mousePosX, &mousePosY);
	lua_pushnumber(L, mousePosX);
	lua_pushnumber(L, mousePosY);
	return 2;
}

int getRelativePositionMouse(lua_State* L){
	int mousePosX;
	int mousePosY;
	SDL_GetRelativeMouseState(&mousePosX, &mousePosY);
	lua_pushnumber(L, mousePosX);
	lua_pushnumber(L, mousePosY);
	return 2;
}

int isDownMouse(lua_State* L){
	Uint8 mask = SDL_GetMouseState(NULL, NULL);
	int button = lua_tointeger(L, -1);
	if(button == mask){
		lua_pushboolean(L,true);
	}
	else lua_pushboolean(L, false);
	return 1;
}

int setPositionMouse(lua_State* L){
	int mousePosX = lua_tointeger(L, -2);
	int mousePosY = lua_tointeger(L, -1);
	SDL_WarpMouse(mousePosX, mousePosY);
	return 0;
}

int setVisibleMouse(lua_State* L){
	int visible = lua_tointeger(L, -1);
	SDL_ShowCursor(visible);
	return 0;
}

int isVisibleMouse(lua_State* L){
	int visible = SDL_ShowCursor(-1);
	lua_pushinteger(L, visible);
	return 1;
}
